import os

# 定义红绿灯类别的字典
rcs_classes = {
    0: 'car',            # 小汽车
    1: 'truck',          # 卡车
    2: 'pedestrian',     # 行人
    3: 'traffic_cone',   # 交通锥
    4: 'forklift',       # 叉车
    5: 'tractor',        # 牵引车
    6: 'flatbed',        # 平板车
    7: 'trailer',        # 拖车
    8: 'cyclist',        # 骑行者（自行车、电动车）
    9: 'bicycle',        # 自行车（电动车）
    10: 'water_horse',   # 水马
    11: 'guardrail',     # 护栏
    12: 'unknown'        # 未知
}

# 统计每种动物类别出现的次数，包括"others"
rcs_count = {rcs: 0 for rcs in rcs_classes.values()}
rcs_count['others'] = 0

# 遍历train和val子文件夹下的所有txt文件
labels_dirs = ['datasets/scene_test/scene-4_image/labels']
for labels_dir in labels_dirs:
    for file_name in os.listdir(labels_dir):
        if file_name.endswith('.txt'):
            file_path = os.path.join(labels_dir, file_name)
            with open(file_path, 'r') as file:
                lines = file.readlines()
                for line in lines:
                    rcs_id = int(line.split()[0])
                    if rcs_id in rcs_classes:
                        rcs_name = rcs_classes[rcs_id]
                    else:
                        rcs_name = 'others'
                    rcs_count[rcs_name] += 1

# 将统计结果写入txt文件
output_file = 'rcs_count_val.txt'
with open(output_file, 'w') as file:
    for rcs, count in rcs_count.items():
        file.write(f'{rcs}: {count}\n')
